@extends('layouts.application')

@section('content')


    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">商城品牌</strong> /
                    <small>Good Brand</small>
                </div>
            </div>
            @include('layouts.shared._flash')

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{Route('shop.brand.create')}}" type="button" class="am-btn am-btn-default"><span
                                        class="am-icon-plus"></span> 新增</a>
                            <button type="button" class="am-btn am-btn-default delete_all">
                                <span class="am-icon-trash-o"></span> 删除
                            </button>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-form-group">
                        <select data-am-selected="{btnSize: 'sm'}">
                            <option value="option1">所有类别</option>
                            <option value="option2">IT业界</option>
                            <option value="option3">数码产品</option>
                            <option value="option3">笔记本电脑</option>
                            <option value="option3">平板电脑</option>
                            <option value="option3">只能手机</option>
                            <option value="option3">超极本</option>
                        </select>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-input-group am-input-group-sm">
                        <input type="text" class="am-form-field">
                        <span class="am-input-group-btn">
            <button class="am-btn am-btn-default" type="button">搜索</button>
          </span>
                    </div>
                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check"><input type="checkbox" class="check_all"></th>
                                <th class="table-id">ID</th>
                                <th class="table-title">缩略图</th>
                                <th class="table-type">名称</th>
                                <th class="table-type">网址</th>
                                <th class="table-author am-hide-sm-only">品牌商品</th>
                                <th class="table-date am-hide-sm-only">品牌描述</th>
                                <th class="table-date am-hide-sm-only">是否显示</th>
                                <th class="table-date am-hide-sm-only">排序</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($brands as $brand)
                                <tr data-id="{{$brand->id}}">
                                    <td><input type="checkbox" value="{{$brand->id}}" class="checked_id" name="checked_id[]"></td>
                                    <td>{{$brand->id}}</td>
                                    <td>
                                        <img src="{{$brand->thumb}}" alt="" style="height: 50px; width: 50px;">
                                    </td>
                                    <td>{{$brand->name}}</td>
                                    <td><a href="{{$brand->url}}" target="_blank">{{$brand->url}}</a></td>
                                    <td class="am-hide-sm-only">
                                        {!! show_brand_products($brand) !!}
                                        {{--<a class="am-btn am-btn-primary am-btn-xs"--}}
                                                                   {{--href="">查看商品</a>--}}
                                    </td>
                                    <td class="am-hide-sm-only">{{str_limit($brand->description,15,'...')}}</td>

                                    <td class="am-hide-sm-only" data-attr="">
                                        {!! is_something($brand,'is_show') !!}

                                    </td>
                                    <td class="am-hide-sm-only">
                                        <input type="text" class="sort_order" value="{{$brand->sort_order}}"
                                               style="width: 50px">
                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a href="{{Route('shop.brand.edit',$brand->id)}}"
                                                   class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                            class="am-icon-pencil-square-o"></span> 编辑
                                                </a>
                                                <a href="javascript:;" class="delete_one am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {{$brands->total()}} 条记录
                            <div class="am-fr">
                                <ul class="am-pagination">
                                    {{$brands->links()}}
                                </ul>
                            </div>
                        </div>
                        <hr/>
                        <p>注：.....</p>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>

@endsection
@section('js')
    <script>
        $(function () {
            //排序
            $('.sort_order').change(function () {
                var info = {
                    id: $(this).parents('tr').data('id'),
                    sort_order: $(this).val()
                }
                $.ajax({
                    type: 'PATCH',
                    url: '{{route('shop.brand.sort_order')}}',
                    data: info,
                    success: function () {
                        location.href = "{{route('shop.brand.index')}}";

                    }
                })
            })
            //改变属性
            $('.change_attr').click(function () {
                var id = $(this).parents('tr').data('id');
                var attr = $(this).attr('data-attr');
                var _this = $(this);
                $.ajax({
                    type: 'PATCH',
                    url: '{{route('shop.brand.change_attr')}}',
                    data: {id: id, attr: attr},
                    success: function () {
                        _this.toggleClass('am-icon-check am-icon-close')
                    }

                });

                return false;
            })
            //删除
            $('.delete_one').click(function () {
                var id = $(this).parents('tr').data('id');
                var _this = $(this);
                $.ajax({
                    type: 'DELETE',
                    url: '/admin/shop/brand/' + id,
                    data: id,
                    success: function () {
                        _this.parents('tr').fadeOut(400)
                    }

                })
                return false;
            })
            //全选 反选
            $('.check_all').click(function () {
                $(':checkbox').prop('checked',this.checked);
            })
            //多选删除
            $('.delete_all').click(function () {
                var length = $('.checked_id:checked').length;
                if(length ==0){
                    alert('您至少选中一条！')
                }
                var checked_id = $('.checked_id:checked').serialize()

                $.ajax({
                    type:'DELETE',
                    url:'{{route('shop.brand.destroy_all')}}',
                    data:checked_id,
                    success:function () {
                        $('.checked_id:checked').each(function () {
                            $(this).parents('tr').fadeOut(400);
                        })
                    }
                })
                return false;
            })

        })
    </script>
@endsection


